#ifndef MT_PROC_H
#define MT_PROC_H

#define MAX_MT_DB 10000

typedef enum
{
	FUNC1,
	FUNC2
}mt_user_def_e;

typedef enum
{
	MT_DB_THREAD_1,
	MT_DB_THREAD_2
}mt_e;

typedef struct mt_db
{
	bool end;
	int  task;
	int	function;
	unsigned long long val;
}mt_db_s;



#define MT_INCR_CNT() {\
		mt_c = ((mt_c + 1) % MAX_MT_DB);\
		}
#define MT_LOG_TIME(_store, _f, _e){\
		struct timespec now; \
		clock_gettime(CLOCK_MONOTONIC, &now);\
		_store.task=_e;\
		_store.function = _f;\
		_store.val=now.tv_sec*1000000000 + now.tv_nsec;}
#define MT_LOG_START(_f, _e){ \
		pthread_mutex_lock(&mt_lock);\
		MT_INCR_CNT();\
		MT_LOG_TIME(mt_db_store[mt_c], _f, _e);\
	 	mt_db_store[mt_c].end=0;\
		pthread_mutex_unlock(&mt_lock); }
#define MT_LOG_END(_f, _e){ \
		pthread_mutex_lock(&mt_lock);\
		MT_INCR_CNT(); \
		MT_LOG_TIME(mt_db_store[mt_c], _f, _e);\
		mt_db_store[mt_c].end=1;\
		pthread_mutex_unlock(&mt_lock); }
#define MT_LOG_DUMP() { mtlogger();}
#define MT_LOG_INIT() { \
		pthread_mutex_init(&mt_lock, NULL); \
		mt_c=0; \
		memset(mt_db_store,0,MAX_MT_DB*sizeof(mt_db_s));};

extern pthread_mutex_t mt_lock;
extern mt_db_s mt_db_store[MAX_MT_DB];

void mtlogger(void);
extern long long mt_c;

#endif
